//
//  UITableViews.swift
//  JXBaseTools
//
//  Created by godox on 2021/11/30.
//

import UIKit

extension JX where Base: UITableView {
    
    
    public func registerCell<T: UITableViewCell>(_ type: T.Type) {
        let identifier = String(describing: type.self)
        base.register(type, forCellReuseIdentifier: identifier)
    }
    public func registerXibCell<T: UITableViewCell>(_ type: T.Type) {
        let identifier = String(describing: type.self)
        base.register(UINib(nibName: "\(type)", bundle: nil), forCellReuseIdentifier: identifier)
    }

   
    public func dequeueReusableCell<T: UITableViewCell>(_ type: T.Type) -> T {
        let identifier = String(describing: type.self)
        guard let cell = base.dequeueReusableCell(withIdentifier: identifier) as? T else {
            fatalError("\(type.self) was not registered")
        }
        return cell
    }
    public func setDelegateAndDataSource(_ delegage: UITableViewDelegate, _ dataSource: UITableViewDataSource){
        base.delegate = delegage
        base.dataSource = dataSource
    }
}
